fix: stop AttributesFromDSN panicking on unix-socket DSNs#625
Open
fix: stop AttributesFromDSN panicking on unix-socket DSNs#625
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #625 +/- ##
=======================================
- Coverage 86.4% 85.9% -0.6%
=======================================
Files 16 16
Lines 752 752
=======================================
- Hits 650 646 -4
Misses 75 75
- Partials 27 31 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
When the DSN uses the protocol(addr) form with a unix-socket path
inside the parentheses (e.g. 'unix(/tmp/mysql.sock)/dbname'),
AttributesFromDSN used to split on '/' before looking for the
wrapping parens. That produced dsn[:pathIndex] = 'unix(' and caused
an out-of-range slice panic further down the chain when
net.SplitHostPort chewed through the unbalanced parenthesis (XSAM#624).
Extract the address-extraction logic into addrFromDSN so the main
function stays under the project's cyclop max-complexity budget, and
check for the '(...)' wrapper first. If the parens are present and
balanced, use the substring between them as the address; otherwise
fall back to the previous 'trim at first /' behaviour so bare
host[:port] and host:port/db forms keep the same semantics.
Closes XSAM#624
Signed-off-by: SAY-5 <SAY-5@users.noreply.github.com>
6f8e3fd to
b6709c2
Compare
Author
|
Thanks @XSAM — addressed both:
Verified locally on macOS, go 1.26.2:
Net diff unchanged behaviourally: bare-address, host:port, and host:port/db forms still resolve the same way; only the protocol(addr) form now extracts the addr from inside the parens first, which is what closes #624. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #624.
AttributesFromDSNfirst split the DSN on the first/to drop the database/params suffix, and then unwrapped anyprotocol(addr)form by takingdsn[openParen+1 : len(dsn)-1]. That ordering is safe for most addresses but breaks as soon as the address itself contains a slash:The
/split happens inside the parentheses, truncatingdsntounix(. The protocol unwrap then computes[openParen+1 : len(dsn)-1]=[5:4], which panics withslice bounds out of range.This PR extracts the
protocol(addr)address first by reading between the matching parens, and only falls back to the first-/trim on bare addresses. That makes the unix-socket case round-trip tosemconv.ServerAddress("/tmp/mysql.sock")and leaves every existing test case unchanged. A regression test is added for the unix-socket DSN.